/*
 * @Author: Yzq
 * @Date: 2021-04-05 15:27:22
 * @LastEditTime: 2021-04-06 18:53:10
 * @LastEditors: Yzq
 */

import I18n from 'i18n-js';
// import * as RNLocalize from 'react-native-localize';
import zh from './strings/zh';
import en from './strings/en';
import User from '../Dao/user';
import {DeviceEventEmitter} from 'react-native';

// const locales = RNLocalize.getLocales();
// const systemLanguage = locales[0]?.languageCode; // 用户系统偏好语言

type Language = 'zh' | 'en';
class Locale {
  static language: Language = '';

  static init() {
    I18n.fallbacks = true;
    I18n.translations = {
      zh,
      en,
    };
    //TODO:从持久化获取到语言，赋值给language
    I18n.currentLocale = 'TODO:';
    this.language = 'TODO:';
  }

  static change = (targetLanaguge: Language) => {
    I18n.locale = targetLanaguge;
    this.language = targetLanaguge;
    //修改语言时，发起通知
    DeviceEventEmitter.emit('changeLanguage');
  };
}

export default Locale;
